package file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo3 {
	public static void main(String[] args) {
		File file = new File("src\\file\\FileDemo.java");
		File des=new File("d:\\haha.txt");
		try {
			FileInputStream in = new FileInputStream(file);
			FileOutputStream out=new FileOutputStream(des);
			byte[] t = new byte[10];
			int n;
			while ((n = in.read(t)) != -1) {				
				out.write(t, 0, n);			
				for (int i = 0; i < n; i++) 
					System.out.print((char) t[i]);
				//System.out.println("===>"+n+" "+in.available());
			}

			in.close();
			out.flush();//刷新文件以免数据丢失
			out.close();
		} catch (FileNotFoundException e) {
			System.err.println("没有找到文件!");
		} catch (IOException e) {
			System.err.println("输入错误!");
		}
	}
}
